﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ScribdNet = Scribd.Net;

namespace TheOutfield.UmbExt.UniversalMediaPicker.Providers.Scribd
{
    public static class ScribdExtensions
    {
        public static MediaItem ToMediaItem(this ScribdNet.Collection col)
        {
            return new MediaItem
            {
                Id = col.ID.ToString(),
                Title = col.Name,
                Icon = UmbracoIcons.FolderOpen,
                HasChildren = col.docCount > 0,
                PreviewImageUrl = "",
                Selectable = false
            };
        }

        public static MediaItem ToMediaItem(this ScribdNet.Category cat)
        {
            return new MediaItem
            {
                Id = cat.ID.ToString(),
                Title = cat.Name,
                Icon = UmbracoIcons.FolderOpen,
                HasChildren = true,
                PreviewImageUrl = "",
                Selectable = false
            };
        }

        public static MediaItem ToMediaItem(this ScribdNet.Document doc)
        {
            var mi = new MediaItem
            {
                Id = doc.DocumentId.ToString(),
                Title = doc.Title,
                Icon = "mediaScribd.gif",
                HasChildren = false,
                PreviewImageUrl = doc.ThumbnailUrl != null ? doc.ThumbnailUrl.ToString() : "",
                Selectable = true
            };

            mi.MetaData.Add("Page Count", doc.PageCount.ToString());
            mi.MetaData.Add("Access Type", doc.AccessType.ToString());
            mi.MetaData.Add("Document Type", doc.DocumentType);
            mi.MetaData.Add("Tags", string.Join(", ", doc.TagList.ToArray()));

            return mi;
        }
    }
}